package com.blb.shiro;

import org.apache.shiro.crypto.RandomNumberGenerator;
import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;

import com.blb.entity.User;
import com.blb.utils.UUIDUtils;

public class PasswordHelper {

    public static void main(String[] args) {

        String hashAlgorithmName = "MD5";
        String credentials = "root";
        int hashIterations = 1024;
        ByteSource credentialsSalt = ByteSource.Util.bytes("root");
        Object obj = new SimpleHash(hashAlgorithmName, credentials, credentialsSalt, hashIterations);
        System.out.println(obj);
    }


    /**
     * 加密后的密码
     *
     * @param user
     */
    public static void getPassword(User user) {
        String salt = UUIDUtils.getID();

        String hashAlgorithmName = "MD5";

        String credentials = user.getPassword();

        int hashIterations = 1024;

        user.setPassword(new SimpleHash(hashAlgorithmName, credentials, ByteSource.Util.bytes(salt), hashIterations).toString());
        user.setSalt(salt);
    }
}
